import { gitDownload } from '@/api/download.js';
const gitDownloadMixin = {
    data() {},
    methods: {
        gitDownload(id, params) {
            const msg = this.$Message.loading({
                content: '下载中...',
                duration: 0,
            });
            let href = `/api/scientific/gitManage/download/${id}?${
                params.name ? `name=${params.name}` : ''
            }${params.branch ? `branch=${params.branch}` : ''}`;
            console.log(href);
            let a = document.createElement('a');
            document.body.appendChild(a);
            a.href = href;
            a.download = ''; //命名下载名称
            a.click(); //点击触发下载
            a.remove();
            setTimeout(msg, 0);
            return;
            // this.$Message.error('下载失败!不存在文件数据！');
            gitDownload(id, params)
                .then((data) => {
                    if (data.data.type == 'application/octet-stream') {
                        const downloadElement = document.createElement('a');
                        const href = window.URL.createObjectURL(data.data);
                        downloadElement.href = href;
                        let name = params.branch
                            ? `${params.name} - ${params.branch}`
                            : params.name;
                        downloadElement.download = '';
                        document.body.appendChild(downloadElement);
                        downloadElement.click();
                        document.body.removeChild(downloadElement); // 下载完成移除元素
                        window.URL.revokeObjectURL(href); // 释放掉blob对象
                        setTimeout(msg, 0);
                        this.$Message.info('下载成功！');
                    } else {
                        setTimeout(msg, 0);
                        this.$Message.error('下载失败!不存在文件数据！');
                    }
                })
                .catch((error) => {
                    setTimeout(msg, 0);
                    this.$Message.error('下载失败!');
                });
        },
    },
};
export { gitDownloadMixin };
